<template>
  <el-dialog
    :title="title"
    :visible.sync="show"
    width="1100px"
    append-to-body
    center
  >
    <div class="search-box">
      <el-form label-width="100px" :inline="true">
        <el-form-item label="合同类型">
          <!-- <el-input v-model="name" /> -->
          <el-select v-model="contractType" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="search()"
        >查询</el-button>
        <el-button
          type="warning"
          icon="el-icon-refresh"
          @click="reset()"
        >重置</el-button>
      </el-form>
    </div>
    <com-table
      v-model="selectRow"
      highlight-current-row
      :data="dataList"
      :columns="columns"
      :total="total"
      @pageChange="pageChange"
    >
      <!-- <template v-slot:name="{row}">
        <a class="com-link" @click="viewDetail(row)">{{ row.name }}</a>
      </template>
      <template v-slot:options="{row}">
        <el-button type="primary" icon="el-icon-edit" size="mini" @click="editBuildUnit(row)">编辑</el-button>
        <el-button type="danger" icon="el-icon-delete" size="mini" @click="delBuildUnit(row)">删除</el-button>
      </template> -->
    </com-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="show = false">取 消</el-button>
      <el-button type="primary" @click="confirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: 'SupplierSelectList',
  props: {
    title: {
      type: String,
      default: ''
    },
    showModal: {
      type: Boolean,
      default: false
    },
    columns: {
      type: Array,
      default() {
        return []
      }
    },
    api: {
      type: Function,
      default() {
        return null
      }
    }
  },
  data() {
    return {
      name: '',
      dataList: [],
      options: [
        {
          value: '7',
          label: '自营管理-销售合同'
        },
        {
          value: '8',
          label: '自营管理-劳务合同'
        },
        {
          value: '9',
          label: '自营管理-材料合同'
        },
        {
          value: '10',
          label: '自营管理-机械设备采购合同'
        },
        {
          value: '11',
          label: '自营管理-机械设备租赁合同'
        },
        {
          value: '12',
          label: '自营管理-其他合同'
        }
      ],
      total: 0,
      pageParams: {
        pageNum: 1,
        pageSize: 10
      },
      contractType: '7',
      selectRow: null
    }
  },
  computed: {
    show: {
      get() {
        return this.showModal
      },
      set(val) {
        this.$emit('update:showModal', val)
      }
    }
  },
  watch: {
    showModal(newValue, oldValue) {
      if (newValue) {
        this.getListData()
      }
    }
  },
  mounted() {
    // this.getListData()
  },
  methods: {
    confirm() {
      this.$emit('getSelectedData', this.selectRow)
      this.show = false
    },
    pageChange(data) {
      this.pageParams = data
      this.getListData()
    },
    reset() {},
    search() {
      this.getListData()
    },
    getListData() {
      const params = {
        ...this.pageParams,
        contractType: this.contractType
      }
      this.api(params).then((res) => {
        const { data, total } = res.data || {}
        if (data) {
          this.dataList = data
          this.total = total - 0
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
